//api.ts
import axios, { type InternalAxiosRequestConfig, type AxiosInstance, type AxiosResponse } from 'axios';
 

const headers = {
  'Authorization': 'Bearer pat_EZrAPDXLrQ0APkR7EpUuxV6eQs7UTtq0Q4Ajc8md5zjKb7w0dKU6QAPSNqdXn4AV', // 替换YOUR_PERSONAL_ACCESS_TOKEN为你的个人访问令牌
  'Content-Type': 'application/json'
};

const http: AxiosInstance = axios.create({
 baseURL: 'https://api.coze.cn',
 timeout: 100000,
 headers:headers
});
 
// 添加请求拦截器
http.interceptors.request.use(
  (config: InternalAxiosRequestConfig) => {
  // 在发送请求之前做些什么
  return config;
  },
  (error: any) => {
  // 处理请求错误a
  return Promise.reject(error);
  },
);
 
// 添加响应拦截器
http.interceptors.response.use(
  (response: AxiosResponse) => {
  // 对响应数据做点什么
  return response;
  },
  (error: any) => {
  // 处理响应错误
  return Promise.reject(error);
  },
);
export const get = <T>(url: string, config?: InternalAxiosRequestConfig): Promise<T> => {
  return http.get<T>(url, config).then(response => response.data);
};
 
export const post = <T>(url: string, data?: any, config?: InternalAxiosRequestConfig): Promise<T> => {
  return http.post<T>(url, data, config).then(response => response.data);
};

export default http;